<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class MY_Email extends CI_Email
{
	public $ci;
	
	public $dir = "rtl";
	
	public $header ="<html><head><style>*{font-family:'Droid Sans Arabic',tahoma,verdana;}</style></head><body dir='rtl'><div style='width:700px;background-color:#ededed;'>
		<table width=100%><tr style=''>
		<td><img src='http://altofola.com/images/mail_head.png' alt='Al Tofola'/></td></tr>";
	
	public $footer = "<tr><td><div style='height:30px;width:100%;background-color:#002F3F'></div></td></tr></table>";
	
	function __construct()
    {
        parent::__construct();
        $this->ci =& get_instance();
    }
    
	function send_mass($ids, $lang='ar', $template_id)
	{
		$config["mailtype"] = "html";
		$config["wordwrap"] = TRUE;
		
		$this->initialize($config);

		//get email settings
		$mail_setting = $this->ci->db->get('mail_setting')->result();
		//get the mail template
		$mail_template = $this->ci->db->where('id', $template_id)->get('mail_template')->result();
		

		$sender_ar 	= $mail_setting[0]->sender_name;
		$sender_en 	= $mail_setting[0]->sender_name_en;
		$from_mail 	= $mail_setting[0]->system_email;
		

		$html_ar_3 ="<tr><td>".$mail_template[0]->content."</td></tr>";

		
		//print_r($ids);
		if(isset($ids) && is_array($ids))
		foreach($ids as $row){
			
			$this->clear();
			
			if($lang=='ar')
				$send_to_name 	= $row->title.' '.$row->name_ar;
			else
				$send_to_name 	= $row->title_en.' '.$row->name_en;
				
			//$data[] =  $send_to_name;
				
				
			$send_to_email 	= $row->email;
			$html_ar_2 ="<tr dir='{$this->dir}'><td dir='{$this->dir}'>$send_to_name</td></tr>";

			$this->to($send_to_email);
			$this->from($from_mail,$sender_en);
			$this->subject($mail_template[0]->subject);
			$this->set_alt_message('Grape System');
			$this->message($this->header.$html_ar_2.$html_ar_3.$this->footer);
			
			$data[$row->con_id]['result'] 	= $this->send();
			$data[$row->con_id]['name'] 	= $send_to_name;
			$data[$row->con_id]['email'] 	= $send_to_email;
			
		}
		
		if(isset($data) && is_array($data))
			return $data;
		else
			return False;
	
	}
	
}
